#include "header.h"

class Rational
{
        int x;
        int y; 
public:
        Rational(int=0, int=1);
        Rational(const Rational&);
        ~Rational(); 
        void afisare();
		friend Rational operator +(Rational, Rational);
        friend Rational operator *(Rational, Rational);
        friend Rational operator -(Rational, Rational);
        friend Rational operator /(Rational, Rational);
		Rational& operator =(Rational&nr);
};

Rational::Rational(int x, int y)
{
        this->x = x;
        this->y = y;
}

Rational::~Rational()
{
}

Rational::Rational(const Rational& z)
{
        this->x = z.x;
        this->y = z.y;
}
void Rational::afisare()
{
        cout << x << "/" << y << " ";
}

Rational& Rational::operator=(Rational&nr)
{
	this->x=nr.x;
	this->y=nr.y;
	return *this;
}

Rational operator +(Rational c1, Rational c2)
{
        Rational tmp;
        tmp.x=c1.x*c2.y+c2.x*c1.y;
        tmp.y=c1.y*c2.y;
        return tmp;
}

Rational operator /(Rational c1, Rational c2)
{
        Rational tmp;
        tmp.x=c1.x*c2.y;
        tmp.y=c1.y*c2.x;
        return tmp;
}

Rational operator -(Rational c1, Rational c2)
{
        Rational tmp;
        tmp.x=c1.x*c2.y-c2.x*c1.y;
        tmp.y=c1.y*c2.y;
        return tmp;
}

Rational operator *(Rational c1, Rational c2)
{
        Rational tmp;
        tmp.x=c1.x*c2.x;
        tmp.y=c1.y*c2.y;
        return tmp;
}

int main()
{
        Rational r1(1,2);
		Rational r2;
		Rational r3(5);
		Rational r4(r1);
		Rational tmp;
		tmp=r1+r2;
		tmp.afisare();
		cout<<endl;
		tmp=r3-r2;
		tmp.afisare();
		cout<<endl;
		tmp=r1*r4;
		tmp.afisare();
		cout<<endl;
		tmp=r2*r3;
		tmp.afisare();
		cout<<endl;
        _getch();
        return 0;
}